﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CarLoanSystem
{
    public partial class panelReportPaymentAmount : UserControl
    {
        public panelReportPaymentAmount()
        {
            InitializeComponent();
            genGridview();
        }

        private void genGridview()
        {
            // gen Grideview
            gvSaleLoan.AutoGenerateColumns = false;

            //Set Columns Count
            gvSaleLoan.ColumnCount = 5;

            //Add Columns
            gvSaleLoan.Columns[0].Name = "EMPLOYEE_ID";
            gvSaleLoan.Columns[0].HeaderText = "รหัสพนักงาน";
            gvSaleLoan.Columns[0].DataPropertyName = "EMPLOYEE_ID";
            gvSaleLoan.Columns[0].Width = 100;

            gvSaleLoan.Columns[1].Name = "EMPLOYEE_NAME";
            gvSaleLoan.Columns[1].HeaderText = "ชื่อ";
            gvSaleLoan.Columns[1].DataPropertyName = "EMPLOYEE_NAME";
            gvSaleLoan.Columns[1].Width = 150;

            gvSaleLoan.Columns[2].Name = "EMPLOYEE_LASTNAME";
            gvSaleLoan.Columns[2].HeaderText = "นามสกุล";
            gvSaleLoan.Columns[2].DataPropertyName = "EMPLOYEE_LASTNAME";
            gvSaleLoan.Columns[2].Width = 150;

            gvSaleLoan.Columns[3].Name = "EMPLOYEE_GROUP";
            gvSaleLoan.Columns[3].HeaderText = "รหัสกลุ่ม";
            gvSaleLoan.Columns[3].DataPropertyName = "EMPLOYEE_GROUP";
            gvSaleLoan.Columns[3].Width = 150;

            gvSaleLoan.Columns[4].Name = "PRINCIPLE";
            gvSaleLoan.Columns[4].HeaderText = "ยอดเงินที่ปล่อย";
            gvSaleLoan.Columns[4].DataPropertyName = "PRINCIPLE";
            gvSaleLoan.Columns[4].Width = 150;

            // end gen gridview
            //gvSaleLoan.DataSource = LoadReportSaleLoan();
        }

        private DataTable LoadReportSaleLoan()
        {
            DataTable dt = DAL.ReportInfoDAL.LoadAllSaleLoan(this.txtGroupId.Text, this.txtEmpId.Text, this.txtName.Text, this.txtLastName.Text);
            return dt;
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            gvSaleLoan.DataSource = LoadReportSaleLoan();
        }

        private void btnRpt_Click(object sender, EventArgs e)
        {
            ShowReportSaleLoan s = new ShowReportSaleLoan(LoadReportSaleLoan());
            s.ShowDialog();
        }
    }
}
